package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entity.Dept;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author : wenchao.long
 * @date : Created in 2020/12/08 14:26 周二
 * @description :
 */
@RestController
@AllArgsConstructor
public class DeptController {

    private static final String REST_URL_PREFIX = "http://localhost:8001";

    private final RestTemplate restTemplate;

    @PostMapping("/consumer/dept/add")
    public Boolean add(@RequestBody Dept dept) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/dept/add", dept, Boolean.class);
    }

    @GetMapping("/consumer/dept/get/{id}")
    public Dept getDept(@PathVariable("id") Long id) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/get/" + id, Dept.class);
    }

    @GetMapping("/consumer/dept/list")
    public List<Dept> list() {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/list", List.class);
    }
}
